import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import Layout from '@/views/layout/index.vue'
import Home from '@/views/home/index.vue'
const router = createRouter({
  history: createWebHashHistory(), //路由匹配模式
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home
        },
        {
          path: 'category/:id',
          component: () => import('@/views/category/index.vue')
        },
        {
          path: 'category/sub/:id',
          component: () => import('@/views/category/sub.vue')
        },
        {
          path: 'goods/:id',
          component: () => import('@/views/goods/index.vue')
        },
        {
          path: '/cart',
          component: () => import('@/views/cart/index.vue')
        }
      ]
    },
    { path: '/login', component: () => import('@/views/login/index.vue') },
    { path: '/demo', component: () => import('@/views/demo/index.vue') },
    { path: '/login/callback', component: () => import('@/views/login/callback.vue') }
  ],
  //页面滚动行为
  scrollBehavior() {
    return { top: 100 } //页面跳转的时候始终滚动到距离顶部的位置
  }
})

export default router
